package com.htfyun.eink.pw.draw.pen.epd.charcoal;

import org.apache.commons.math3.special.Erf;


public class MathUtils {

    //返回 新生成的 width
    public static float computeTiltAndOrientation(float tiltX, float tiltY, float tiltScale, float width) {
        double pi = Math.PI;
        int degree180 = 180;
        double r0 = tiltX * pi / degree180;
        double r1 = tiltY * pi / degree180;

        double sin0 = Math.sin(r0);
        double cos0 = Math.cos(r0);

        double sin1 = Math.sin(r1);
        double cos1 = Math.cos(r1);

        double cos = cos0 * cos1;
        double acos = Math.acos(cos);

        double atan = Math.atan2(-sin0, sin1);

        double val = 2.2D;
        double pow = Math.pow(acos, val);
        double result = tiltScale * pow;

        return width * ((int) ((result + 1.0) * 5.0) * 0.2f);
    }

    public static float distanceBetween(float x0, float y0, float x1, float y1) {
        return (float) Math.hypot(x1 - x0, y1 - y0);
    }

    public static double erf(double x) {
        return Erf.erf(x);
    }

    public static int uint8_multiple(int a1, int a2) {
        int val = ((0xff & a2) * (0xff & a1) + 0x80);
        return (0xff & ((val + (val >> 8)) >> 8));
    }

}
